import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

def draw(path):
    data = pd.read_csv(path)
    # 计算和加速度
    import math as m
    vect = []
    for item in data.values:
        # print(x)
        vect.append(m.sqrt(item[1]*item[1]+item[2]*item[2]+item[3]*item[3]))
    x = data['t']
    plt.figure(dpi=300)
    plt.plot(x, data['ax'], label='ax')
    plt.plot(x, data["ay"], label='ay')
    plt.plot(x, data["az"], label='az')
    plt.plot(x, vect, label='sum')
    plt.title("acceleration-xyz\n" + path)
    plt.xlabel('s')
    plt.ylabel('g')
    plt.legend()
    plt.savefig(f"h3/task1/img/accelerate.png")

    plt.figure(dpi=300)
    plt.plot(x, data['gx'], label='gx')
    plt.plot(x, data["gy"], label='gy')
    plt.plot(x, data["gz"], label='gz')
    plt.title("Angular acceleration-xyz\n"+path)
    plt.xlabel('s')
    plt.ylabel('g')
    plt.legend()
    plt.savefig(f"h3/task1/img/gypo.png")
if __name__ == "__main__":
    draw("h3/task1/data/mpu_data_21_1647794241.csv")